/*
 * @Author: zoufengfan
 * @Date: 2022-08-15 17:18:19
 * @LastEditTime: 2023-04-10 11:05:17
 * @LastEditors: zoufengfan
 */
import { defineConfig } from "yapi-to-typescript";

// 使用示例
// url: /a/b/c
// import { c } from '_api/{YAPI的ProjectName}/a/b'

export const serverUrl = "http://172.16.14.34:3001";

export default defineConfig([
  {
    serverUrl,
    // typesOnly: true,
    devEnvName: "local",
    target: "typescript",
    reactHooks: {
      enabled: false,
    },
    prodEnvName: "production",
    // 注释
    comment: {
      updateTime: false,
      tag: false,
    },
    requestFunctionFilePath: "src/YApi/request.ts",
    // 对接过接口后不能随便更改
    getRequestFunctionName(interfaceInfo, changeCase) {
      let str = interfaceInfo.query_path.path.match(/(?!\/)[\w\d-{}]+$/)?.[0]; //  /a/b/c  => c
      return "api_" + str;
    },
    // 对接过接口后不能随便更改
    outputFilePath: (interfaceInfo) => {
      let path = "";
      let arr = interfaceInfo.query_path.path.split("/"); //  /a-b/{c}/d/e
      arr.length -= 1; //  /a-b/{c}/d/e  =>  /a-b/{c}/d
      path = arr.join("/");

      path = path.replace(/{/g, "").replace(/}/g, "");

      console.log(path);

      return `src/yapi/api/${interfaceInfo._project.name}${path}.ts`;
    },
    dataKey: "data",
    projects: [
      {
        token:
          "cff84201e0026a23772115ad17ba4c43546c03f18cb939ed7a70f82804c108ba",
        categories: [{ id: 0 }],
        preproccessInterface(interfaceInfo) {
          return interfaceInfo.status === "done" ? interfaceInfo : false;
        },
      },
    ],
  },
]);
